<?php
    header("Content-type: text/html; charset=utf-8");
    session_start();
    require "../connection.php";
    try{
        $username = $_POST['username'];
        $password = $_POST['password'];
        if($username!=NULL && $password !=NULL){
            $sql = "select * from admin where username='".$username."' and password=".$password;
            $result = $conn->doSql($sql);
            if($result){
                $nickname= $result[0]['nickname'];
                $_SESSION['nickname'] = $nickname;
                echo "<script>location.href='index.php'</script>";
            }
            echo "<script>alert('用户名密码错误');location.href='login.html'</script>";



        }else{
            echo "<script>alert('登录失败');location.href='login.html'</script>";
        }
    }catch(Exception $e){
        print_r($e->getMessage());
    }

    $conn->close();
?>